<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class TagGroup extends BaseModel {
    use HasFactory;

    protected $table = "tag_group";
    protected $fillable = ['name', 'scope','tag_num','site_id'];
    protected $casts = [
        'created_at' => 'datetime:Y-m-d',
        'updated_at' => 'datetime:Y-m-d',
    ];
    protected $with = ['tags:id,name'];

    public function tags() {
        return $this->belongsToMany("App\Models\Tag", 'tag_group_tag', 'group_id', 'tag_id')->orderByPivot('sort')->withPivot("sort");
    }

    public function getTagsAttribute() {
        return $this->tags()->get(['tag_id', 'name'])->keyBy('tag_id');
    }



}
